<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课程列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>课程名称：</p>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <p>状态：</p>
                            <select name="status" th:with="type=${@dict.getType('lesson_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="lesson:lesson:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editFull()"
               shiro:hasPermission="lesson:lesson:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="lesson:lesson:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('lesson:lesson:edit')}]];
        var removeFlag = [[${@permission.hasPermi('lesson:lesson:remove')}]];
        var statusDatas = [[${@dict.getType('lesson_status')}]];
        var typeDatas = [[${@dict.getType('lesson_type')}]];
        var channelDatas = [[${@dict.getType('lesson_channel')}]];
        var provideMethodDatas = [[${@dict.getType('lesson_provide_method')}]];
        var prefix = ctx + "lesson/lesson";
        var bannerPrefix = ctx + "lesson/banner";
        var posterPrefix = ctx + "lesson/poster";
        var coursePrefix = ctx + "lesson/course";
        var guidePrefix = ctx + "lesson/lessonguide";
        var catalogPrefix = ctx + "lesson/lessoncatalog";
        var codePrefix = ctx + "lesson/lessoncode";

        $(function() {
            var options = {
                sortName: "createdTime",
     		    sortOrder: "desc",
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "课程",
                detailView: true,
		        detailFormatter: detailFormatter,
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : '课程ID',
                    visible: false
                },
                {
                    field : 'name', 
                    title : '课程名称',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field : 'yuan',
                    title : '原价'
                },
                {
                    field : 'discountYuan',
                    title : '折扣价格'
                },
                {
                    field : 'regStartTime', 
                    title : '报名开始',
                    visible: false
                },
                {
                    field : 'regEndTime', 
                    title : '报名结束',
                    visible: false
                },
                {
                    field : 'autoDeployTime', 
                    title : '自动上架时间',
                    visible: false
                },
                {
                    field : 'autoUndeployTime', 
                    title : '自动下架时间',
                    visible: false
                },
                {
                    field : 'normalTags', 
                    title : '常规标签',
                    visible: false
                },
                {
                    field : 'hotTags', 
                    title : '红火标签',
                    visible: false
                },
                {
                    field : 'capacity', 
                    title : '限购名额',
                },
                {
                    field : 'showMain', 
                    title : '是否首页显示',
                    formatter: function(value, row, index) {
                    	if(value == 1){
                      	   return '<i class=\"fa fa-toggle-on text-info fa-2x\" )"></i>'
                        }else{
                      	   return '<i class=\"fa fa-toggle-off text-info fa-2x\" )"></i>'
                        }
                    }
                },
                {
                    field : 'recomMain',
                    title : '是否首页推荐',
                    formatter: function(value, row, index) {
                    	if(value == 1){
                      	   return '<i class=\"fa fa-toggle-on text-info fa-2x\" )"></i>'
                        }else{
                      	   return '<i class=\"fa fa-toggle-off text-info fa-2x\" )"></i>'
                        }
                    }
                },
                {
                    field : 'test',
                    title : '是否测试课',
                    formatter: function(value, row, index) {
                    	if(value == 1){
                      	   return '<i class=\"fa fa-toggle-on text-info fa-2x\" )"></i>'
                        }else{
                      	   return '<i class=\"fa fa-toggle-off text-info fa-2x\" )"></i>'
                        }
                    }
                },
                {
                    field : 'tagNames',
                    title : '分类标签',
                    visible: false
                },
                {
                    field : 'blockNames',
                    title : '所属板块',
                    visible: false
                },
                {
                    field : 'remark', 
                    title : '备注',
                    visible: false
                },
                {
                    field : 'createdTime', 
                    title : '创建时间',
                    visible: false
                },
                {
                    field : 'status', 
                    title : '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="courseList(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>章节列表</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="bannerList(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>Banner编辑</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="posterList(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>海报编辑</a> ');
                        if(row.type == 4){
                           actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="guideList(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>指引编辑</a> ');
                           actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="catalogList(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>目录编辑</a> ');
                           actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="codeList(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>激活码管理</a> ');
                        }
                        if(row.status == 0){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="updateStatus(\'' + row.id + '\', 1)"><i class="fa fa-approve"></i>上架</a>');
                        }else if(row.status == 1){
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="updateStatus(\'' + row.id + '\', 0)"><i class="fa fa-remove"></i>取消上架</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="updateStatus(\'' + row.id + '\', 2)"><i class="fa fa-remove"></i>下架</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function bannerList(lessonId) {
		    var url = bannerPrefix + "/" + lessonId;
		    $.modal.openTab("Banner列表", url);
		}

		function posterList(lessonId) {
		    var url = posterPrefix + "/" + lessonId;
		    $.modal.openTab("海报列表", url);
		}

	    function guideList(lessonId) {
		    var url = guidePrefix + "/" + lessonId;
		    $.modal.openTab("指引列表", url);
		}

		function catalogList(lessonId) {
		    var url = catalogPrefix + "/" + lessonId;
		    $.modal.openTab("目录列表", url);
		}

	    function codeList(lessonId) {
		    var url = codePrefix + "/" + lessonId;
		    $.modal.openTab("激活码管理", url);
		}

		function courseList(lessonId) {
		    var url = coursePrefix + "/" + lessonId;
		    $.modal.openTab("章节列表", url);
		}

		function updateStatus(lessonId, status){
		   	let msg ;
		   	switch(status){
		   	   case 0:
		   	      msg = "确定要取消上架该课程吗?取消上架后可以重新上架";
		   	      break;
		   	   case 1:
		   	      msg = "确定上架该课程吗?";
		   	      break;
		   	   case 2:
		   	      msg = "确定要下架该课程吗?下架后不能重新上架";
		   	      break;
		   	}
		    $.modal.confirm(msg, function() {
				$.operate.post(prefix + "/updateStatus/" + lessonId, { "status": status});
		    })
		}

		function detailFormatter(index, row) {
        	var html = [];
        	var typeName = $.table.selectDictLabel(typeDatas, row.type);
            html.push('<p><b>课程类型:</b> ' + typeName + '</p>');
            if(row.type == 4)
            {
                var channelName = $.table.selectDictLabel(channelDatas, row.channel);
                html.push('<p><b>课程渠道:</b> ' + channelName + '</p>');

                var provideMethodName = $.table.selectDictLabel(provideMethodDatas, row.provideMethod);
                html.push('<p><b>发放形式:</b> ' + provideMethodName + '</p>');
            }
        	html.push('<p><b>所属版块:</b> ' + row.blockNames + '</p>');
        	html.push('<p><b>分类标签:</b> ' + row.tagNames + '</p>');
        	html.push('<p><b>常规标签:</b> ' + row.normalTags + '</p>');
        	html.push('<p><b>火红标签:</b> ' + row.hotTags + '</p>');
        	html.push('<p><b>报名开始:</b> ' + row.regStartTime + '</p>');
        	html.push('<p><b>报名结束:</b> ' + row.regEndTime + '</p>');
        	html.push('<p><b>自动上架时间:</b> ' + row.autoDeployTime + '</p>');
        	html.push('<p><b>自动下架时间:</b> ' + row.autoUndeployTime + '</p>');
        	return html.join('');
       	}


</script>
</body>
</html>